package com.zonski.jbots.engine;

import com.zonski.jbots.engine.entity.MovingEntity;

/**
 * A resource that can be used
 */
public abstract class UsableResource extends Resource
{
    private boolean beingUsed;
    private boolean toggle;
    private int direction;
    
    public UsableResource()
    {
    }

    public void startUsing(int direction)
    {
        this.beingUsed = true;
        this.toggle = true;
        this.direction = direction;
        ((MovingEntity)this.getOwner()).stopMovement(this);
    }

    public void stopUsing()
    {
        this.beingUsed = false;
        ((MovingEntity)this.getOwner()).allowMovement(this);
    }

    public boolean isBeingUsed()
    {
        return this.beingUsed || this.toggle;
    }

    public int getDirection()
    {
        return this.direction;
    }

    public void update(Engine engine)
        throws Exception
    {
        super.update(engine);
        this.toggle = false;
    }
}
